use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};

fn main() -> anyhow::Result<()> {
    let host = cpal::default_host();
    let od = host.default_output_device().unwrap();
    let stream = od.build_output_stream(
        &od.default_output_config()?.config(),
        |d: &mut [i16], _info| {
            for (i, ele) in d.iter_mut().enumerate() {
                *ele = i as i16;
            }
        },
        |_e| {},
        None,
    )?;

    stream.play()?;
    std::thread::sleep(std::time::Duration::from_secs(5));
    stream.pause()?;

    Ok(())
}
